class RunnableDemo implements Runnable {
    private Thread thread;
    private String threadName;

    // 构造函数
    RunnableDemo(String name) {
        threadName = name;
        System.out.println("Create thread name is:" + threadName);
    }

    // 线程就绪
    public void run() {
        System.out.println("Running" + threadName);

        try {
            for (int i = 4; i > 0; i--) {
                System.out.println("Thread: " + threadName + "," + i);
                Thread.sleep(50);
            }
        } catch (Exception e) {
            System.out.println("Thread " + threadName + " interrupted.");
        }
        System.out.println("Thread " + threadName + " exiting.");
    }

    // 线程运行
    public void start() {
        System.out.println("Starting: " + threadName);
        if (thread == null) {
            thread = new Thread(this, threadName);
            thread.start();
        }
    }
}

public class TestThread {
    public static void main(String[] args) {
        RunnableDemo rDemo1 = new RunnableDemo("Thread-1");
        rDemo1.start();

        RunnableDemo rDemo2 = new RunnableDemo("Thread-2");
        rDemo2.start();
    }
}